package cn.com.sina.alan.oauth.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.builders.WebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;


/**
 * Created by wanghongfei(hongfei7@staff.sina.com.cn) on 9/12/16.
 */
@Configuration
public class AlanOAuthWebConfig extends WebSecurityConfigurerAdapter {



    @Override
    protected void configure(HttpSecurity http) throws Exception {
    	 http.authorizeRequests()  
	         .antMatchers("/", "/home").permitAll()  
	         .antMatchers("/admin/**").access("hasRole('ADMIN')")  
	         .antMatchers("/db/**").access("hasRole('ADMIN') and hasRole('DBA')")  
	         .and().formLogin().loginPage("/login")  
	         .usernameParameter("ssoId").passwordParameter("password")  
	         .and().csrf()  
	         .and().exceptionHandling().accessDeniedPage("/Access_Denied");  
    }

    @Autowired
    public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
        auth
            .inMemoryAuthentication()
                .withUser("user").password("password").roles("USER");
    }

}
